/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands.template;

import org.eclipse.gef.commands.Command;
import org.eclipse.uml2.uml.ParameterableElement;
import org.eclipse.uml2.uml.TemplateParameterSubstitution;

/**
 * 
 */
public class DeleteReferenceFromTemplateParameterSubstitutionCommand extends Command {
	
	/**
	 * ParameterableElement to delete.
	 */
	private ParameterableElement child;
	
	/**
	 * Owner of the parameterable element to delete.
	 */
	private TemplateParameterSubstitution parent;
	
	
	/**
	 * Default Constructor.
	 * 
	 * @param child 
	 */
	public DeleteReferenceFromTemplateParameterSubstitutionCommand(TemplateParameterSubstitution parent, ParameterableElement child) {
		this.child = child;
		this.parent = parent;		
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#canUndo()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public boolean canUndo() {
		return child != null;
	}
	
	public boolean canRedo() {
		return child != null ;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#execute()
	 */
	/**
	 * 
	 */
	@Override
	@SuppressWarnings("unchecked")
	public void execute() {
		parent.getActuals().remove(child) ;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#redo()
	 */
	/**
	 * 
	 */
	@Override
	public void redo() {
		execute();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
	/**
	 * 
	 */
	@Override
	@SuppressWarnings("unchecked")
	public void undo() {
		parent.getActuals().remove(child) ;
	}
}
